package com.crp.unitalinforbaseplat.app.sys.controller;

import com.crp.unitalinforbaseplat.app.core.Message;
import com.crp.unitalinforbaseplat.app.core.utils.EmptyUtils;
import com.crp.unitalinforbaseplat.app.sys.controller.common.BaseController;
import com.crp.unitalinforbaseplat.app.sys.entity.Permission;
import com.crp.unitalinforbaseplat.app.sys.service.PermissionService;
import com.crp.unitalinforbaseplat.app.unitalinforbaseplat.entity.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/unitlinforbase/permission/")
public class PermissionController extends BaseController {

    @Autowired
    PermissionService permissionService;

    // 返回用户列表视图
    @RequestMapping("index.crp")
    ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("backend/sys/permission/list");
        modelAndView.addObject("userName",getUserName());
        modelAndView.addObject("roleName",getRoleName());
        return modelAndView;
    }

    // 返回用户列表视图
    @RequestMapping("update/index.crp")
    ModelAndView updateIndex(Long id) {
        ModelAndView modelAndView = new ModelAndView("backend/sys/permission/update");
        if(!EmptyUtils.isEmpty(id)){
            modelAndView.addObject("permission",permissionService.updateInit(id));
        }else{
            modelAndView.addObject("permission",new Permission());
        }
        modelAndView.addObject("userName",getUserName());
        modelAndView.addObject("roleName",getRoleName());
        return modelAndView;
    }

    @RequestMapping("list.crp")
    @ResponseBody
    PageBean<Permission> list(Permission permission){
        PageBean<Permission> pageBean = new PageBean<Permission>();
        pageBean.setParameter(permission);
        return permissionService.list(pageBean);
    }


    @RequestMapping("saveOrUpdate.crp")
    @ResponseBody
    Message saveOrUpdate(Permission permission){
        return permissionService.saveOrUpdate(permission);
    }

    @RequestMapping("delete.crp")
    @ResponseBody
    Message delete(Long[] id){
        return permissionService.delete(id);
    }

//    @RequestMapping("listUserInfo.crp")
//    @ResponseBody
//    public List<SelectEntity> listUserInfo(Long roleId) throws Exception{
//        User sysUserInfo = new User();
//        sysUserInfo.setRoleIdStr(roleId);
//        return permissionService.listUserInfo(sysUserInfo);
//    }


}
